<?php
/**
 * 网站首页控制器
 */
class IndexController extends CommonController{
    //动作方法
    public function index(){		
		//首页轮播图数据调用
		$slide = C('SOLIDE_CONFIG');
		$this->assign('slide',$slide);
		
		//一楼食品区数据调用
		 //一楼tab1食品
		 $food = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=609")->ORDER('goods_addTime')->limit(8)->all();
		 //组合图片途径 默认调用第一张图
		 foreach($food as $k => $v){
			$imgUrl = array_filter(explode(',', $v['goods_info_smallIMg']));//将字符串转数组 并过滤掉空值
			if($imgUrl){
				$imgUrl = array_splice($imgUrl,0,1);
				$food[$k]['imgUrl'] = $imgUrl[0];//抽取一张做列表图
			}
		 }
		 $this->assign('food',$food);
		 //tab1 栏目
		 $foodcate = M('category')->where("pid=8")->limit(11)->all();
		 $this->assign('foodcate',$foodcate);
		 //一楼tab2酒水
		  $wine = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=601")->ORDER('goods_addTime')->limit(8)->all();
		  $winecate = M('category')->where("pid in(69,71,72)")->limit(14)->all();
		  $this->assign('wine',$wine);
		  $this->assign('winecate',$winecate); 
		 //一楼tab3家纺
		  $home = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=502")->ORDER('goods_addTime')->limit(8)->all();
		  $homecate = M('category')->where("pid=55")->limit(11)->all();
		  $this->assign('home',$home);
		  $this->assign('homecate',$homecate); 
		  
		  
		//二楼食品区数据调用
		 //二楼电脑办公
		 $pc = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=349")->ORDER('goods_addTime')->limit(9)->all();
		 $this->assign('pc',$pc);
		 //tab1 栏目
		 $pccate = M('category')->where("pid in(43,44)")->limit(15)->all();
		 $this->assign('pccate',$pccate);
		 //二楼tab2彩电影音
		  $tv = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=786")->ORDER('goods_addTime')->limit(9)->all();
		  $tvcate = M('category')->where("pid in(88,89,92,92)")->limit(14)->all();
		  $this->assign('tv',$tv);
		  $this->assign('tvcate',$tvcate); 
		 //二楼tab3生活厨卫
		  $bath = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=486")->ORDER('goods_addTime')->limit(9)->all();
		  $bathcate = M('category')->where("pid in(51,54)")->limit(11)->all();
		  $this->assign('bath',$bath);
		  $this->assign('bathcate',$bathcate); 
		  
		//三楼母婴美妆数据调用
		 //三楼玩具童车
		 $baby = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=163")->ORDER('goods_addTime')->limit(9)->all();
		 $this->assign('baby',$baby);
		 //tab1 栏目
		 $babycate = M('category')->where("pid in(19,54)")->limit(13)->all();
		 $this->assign('babycate',$babycate);
		 //三楼tab2孕婴服饰
		  $babyClothes = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=157")->ORDER('goods_addTime')->limit(9)->all();
		  $babyClothescate = M('category')->where("pid in(19,54)")->order('rand()')->limit(12)->all();
		  $this->assign('babyClothes',$babyClothes);
		  $this->assign('babyClothescate',$babyClothescate); 
		 //三楼tab3美容护理
		  $cosmetology = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=166")->ORDER('goods_addTime')->limit(9)->all();
		  $cosmetologycate = M('category')->where("pid in(19,54)")->order('rand()')->limit(12)->all();
		  $this->assign('cosmetology',$cosmetology);
		  $this->assign('cosmetologycate',$cosmetologycate); 
		  //三楼tab4个人护理
		  $person = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=498")->ORDER('goods_addTime')->limit(9)->all();
		  $personcate = M('category')->where("pid in(19,54)")->order('rand()')->limit(13)->all();
		  $this->assign('person',$person);
		  $this->assign('personcate',$personcate); 
		  
		//四楼母婴美妆数据调用
		 //四楼珠宝手表
		 $watch = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=578")->ORDER('goods_addTime')->limit(9)->all();
		 $this->assign('watch',$watch);
		 //tab1 栏目
		 $watchcate = M('category')->where("pid in(66,67,68)")->limit(13)->all();
		 $this->assign('watchcate',$watchcate);
		 //四楼鞋靴箱包
		  $bag = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=564")->ORDER('goods_addTime')->limit(9)->all();
		  $bagcate = M('category')->where("pid in(63,64,65)")->order('rand()')->limit(12)->all();
		  $this->assign('bag',$bag);
		  $this->assign('bagcate',$bagcate); 
		 //四楼tab3运动化外
		  $sport = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=1003")->ORDER('goods_addTime')->limit(9)->all();
		  $sportcate = M('category')->where("pid in(97,98)")->order('rand()')->limit(12)->all();
		  $this->assign('sport',$sport);
		  $this->assign('sportcate',$sportcate); 
		  //四楼tab4汽车用品
		  $car = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where("category_cid=735")->ORDER('goods_addTime')->limit(9)->all();
		  $carcate = M('category')->where("pid in(79,80,81)")->order('rand()')->limit(10)->all();
		  $this->assign('car',$car);
		  $this->assign('carcate',$carcate); 
		  
		  //0层中间数据调用
		  $zeroOne = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where('category_cid = 157')->limit(6)->all();
			//重组热们商品图片
			foreach($zeroOne as $k => $v){
				$imgUrl = array_filter(explode(',', $v['goods_info_smallIMg']));//将字符串转数组 并过滤掉空值
				//计算折扣
				$sale = round($v['goods_mall'] / $v['goods_market'] *10,1);
				$zeroOne[$k]['sale']  = $sale;
				if($imgUrl){
					$imgUrl = array_splice($imgUrl,0,1);
					if($imgUrl[0]){
						$zeroOne[$k]['imgUrl'] = $imgUrl[0];//抽取一张做列表图
					}else{
						$zeroOne[$k]['imgUrl'] = '0';
					}				
				}else{
					$zeroOne[$k]['imgUrl'] = '0';
				}
			}
		  $this->assign('zeroOne',$zeroOne);
		  
		  $zerotwo = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where('category_cid = 166')->limit(6)->all();
			foreach($zerotwo as $k => $v){
				$imgUrl = array_filter(explode(',', $v['goods_info_smallIMg']));//将字符串转数组 并过滤掉空值
				//计算折扣
				$sale = round($v['goods_mall'] / $v['goods_market'] *10,1);
				$zerotwo[$k]['sale']  = $sale;
				if($imgUrl){
					$imgUrl = array_splice($imgUrl,0,1);
					if($imgUrl[0]){
						$zerotwo[$k]['imgUrl'] = $imgUrl[0];//抽取一张做列表图
					}else{
						$zerotwo[$k]['imgUrl'] = '0';
					}				
				}else{
					$zerotwo[$k]['imgUrl'] = '0';
				}
			}
		  $this->assign('zerotwo',$zerotwo);
		  $zerothree = M()->JOIN("__goods__ g join __goods_info__ g2 on g.gid = g2.goods_gid")->where('category_cid = 345')->limit(6)->all();
			foreach($zerothree as $k => $v){
				$imgUrl = array_filter(explode(',', $v['goods_info_smallIMg']));//将字符串转数组 并过滤掉空值
				//计算折扣
				$sale = round($v['goods_mall'] / $v['goods_market'] *10,1);
				$zerothree[$k]['sale']  = $sale;
				if($imgUrl){
					$imgUrl = array_splice($imgUrl,0,1);
					if($imgUrl[0]){
						$zerothree[$k]['imgUrl'] = $imgUrl[0];//抽取一张做列表图
					}else{
						$zerothree[$k]['imgUrl'] = '0';
					}				
				}else{
					$zerothree[$k]['imgUrl'] = '0';
				}
			}
		  $this->assign('zerothree',$zerothree);
			
			 
        $this->dis('index');
    }
	
	
	//二维码实例化
	public function code(){
		$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		$code = new Qrcode($url);
		$code->code($url);
//		echo $url;
	}
}
